import { View } from '@tarojs/components'
import Taro, { Component } from '@tarojs/taro'
import TaroParser from 'taro-parse'

export default class MdPreview extends Component {
    constructor() {
        super(...arguments)
        this.state = {}
    }

    componentWillMount() {
    }
    imgClick = (src) => {
        Taro.previewImage({ urls: [src] })
    }
    linkClick = (href) => {
        Taro.setClipboardData({ data: href }).then(() => {
            Taro.showToast({ title: '链接已复制' })
        })
    }

    render() {
        return (
            <View style={{ marginTop: (this.props.marginTop || '100rpx'), marginBottom: (this.props.marginBottom || '120rpx') }}>
                <h4>{this.props.title}</h4>
                <TaroParser
                    type='markdown'
                    theme='light'
                    onImgClick={this.imgClick}
                    onLinkClick={this.linkClick}
                    yumlApi='https://md.werfei.com/?yuml'
                    latexApi='https://md.werfei.com/?tex'
                    content={this.props.content}
                />
            </View>
        )
    }
}